package com.aloda.controller.user;

import com.aloda.dto.TeamAddDTO;
import com.aloda.dto.TeamJoinDTO;
import com.aloda.dto.TeamPageByTagDTO;
import com.aloda.result.Result;
import com.aloda.service.TeamService;
import com.aloda.vo.TeamAddVO;
import com.aloda.vo.TeamInfoVO;
import com.aloda.vo.TeamJoinVO;
import com.aloda.vo.UserTeamPageVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "客户端队伍相关接口")
@RestController("userTeamController")
@RequestMapping("/user/team")
public class TeamController {

    @Resource
    private TeamService teamService;

    /**
     * 增加队伍
     *
     * @param teamAddDTO
     * @return
     */
    @Operation(summary = "增加队伍")
    @PostMapping
    public Result addTeam(@RequestBody TeamAddDTO teamAddDTO) {
        log.info("增加队伍：{}", teamAddDTO);
        TeamAddVO teamAddVO = teamService.addTeam(teamAddDTO);
        return Result.success(teamAddVO);
    }

    /**
     * 获取用户加入的队伍（滚动分页）
     *
     * @param currentPage
     * @return
     */
    @Operation(summary = "获取加入的队伍")
    @GetMapping("/{current}")
    public Result<List<UserTeamPageVO>> getUserTeam(@PathVariable(name = "current") Integer currentPage) {
        List<UserTeamPageVO> list = teamService.getUserTeam(currentPage);
        return Result.success(list);
    }

    /**
     * 获取用户创建的队伍
     *
     * @param currentPage
     * @return
     */
    @Operation(summary = "获取用户创建的队伍")
    @GetMapping("/created/{current}")
    public Result<List<UserTeamPageVO>> getUserCreatedTeam(@PathVariable(name = "current") Integer currentPage) {
        List<UserTeamPageVO> list = teamService.getUserCreatedTeam(currentPage);
        return Result.success(list);
    }

    /**
     * 获取队伍详细信息
     *
     * @param id
     * @return
     */
    @Operation(summary = "获取队伍详细信息")
    @GetMapping("/info/{id}")
    public Result<TeamInfoVO> getTeamDetailInfo(@PathVariable Long id) {
        TeamInfoVO teamInfoVO = teamService.getTeamDetailInfo(id);
        return Result.success(teamInfoVO);
    }

    /**
     * 根据标签查找队伍
     * @param teamPageByTagDTO
     * @return
     */
    @Operation(summary = "根据标签查找队伍")
    @PostMapping("/tag/search")
    public Result<List<UserTeamPageVO>> getTeamByTags(@RequestBody TeamPageByTagDTO teamPageByTagDTO) {
        log.info("标签：{}",teamPageByTagDTO);
        List<UserTeamPageVO> list = teamService.getTeamByTags(teamPageByTagDTO);
        return Result.success(list);
    }

    /**
     * 用户加入队伍
     * @param teamJoinDTO
     * @return
     */
    @Operation(summary = "用户加入队伍")
    @PostMapping("/join")
    public Result userJoinTeam(@RequestBody TeamJoinDTO teamJoinDTO) {
        TeamJoinVO teamJoinVO = teamService.userJoinTeam(teamJoinDTO);
        return Result.success(teamJoinVO);
    }
}
